package com.kd.d5000acquire.util;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.codehaus.xfire.client.Client;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.net.URL;
import java.util.Queue;

//@Profile("!test")
@Component
@Slf4j
@Data
public class DMUtil {
    @Value("${my.xfile.url}")
    public String wsdlUrl;
    @Value("${my.xfile.sql}")
    public String sql;
    @Value("${my.xfile.code}")
    public String code;
    @Value("${my.xfile.fun}")
    public String fun;



    private Client wsClient;

    public void getAll() throws InterruptedException {

    }

    public Object[] getBySql(String sql) {
        if (wsClient == null ){
            this.connection();
        }
        try {
            Object[] invoke = wsClient.invoke(fun, new Object[]{sql, code});
            log.info("收到内容为:  " + invoke[0].toString());
            log.info("收到类型为:  " + invoke[0].getClass().toString());
            return invoke;
        } catch (Exception e) {
            log.error("获取sql失败",e);
            return null;
        }
    }

    public void connection() {
        log.info("开始链接XFile" +
                "\n参数为:" +
                "\n参数wsdlUrl:"+ wsdlUrl +
                "\n参数code:"+ code +
                "\n参数fun:"+ fun);
        try {
            this.wsClient = new Client(new URL(wsdlUrl));
            log.info("连接成功");
        }catch (Exception e){
            log.error("执行异常",e);
        }
    }
}

